package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.wechat.domain.WechatUserPointsRecord;
import com.ruoyi.wechat.mapper.WechatUserPointsRecordMapper;
import com.ruoyi.wechat.service.IWechatUserPointsRecordService;
import com.ruoyi.wechat.service.IWechatUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 微信用户积分记录Service业务层处理
 *
 * @author KevenPotter
 * @date 2024-07-17 10:10:16
 */
@Service
@RequiredArgsConstructor
public class WechatUserPointsRecordServiceImpl implements IWechatUserPointsRecordService {

    private final WechatUserPointsRecordMapper wechatUserPointsRecordMapper;
    private final IWechatUserService wechatUserService;
    private final ISysUserService userService;

    /**
     * 查询微信用户积分记录
     *
     * @param id 微信用户积分记录主键
     * @return 微信用户积分记录
     */
    @Override
    public WechatUserPointsRecord selectWechatUserPointsRecordById(Long id) {
        return wechatUserPointsRecordMapper.selectWechatUserPointsRecordById(id);
    }

    /**
     * 查询微信用户积分记录列表
     *
     * @param wechatUserPointsRecord 微信用户积分记录
     * @return 微信用户积分记录
     */
    @Override
    public List<WechatUserPointsRecord> selectWechatUserPointsRecordList(WechatUserPointsRecord wechatUserPointsRecord) {
        return wechatUserPointsRecordMapper.selectWechatUserPointsRecordList(wechatUserPointsRecord);
    }

    /**
     * 新增微信用户积分记录
     *
     * @param wechatUserPointsRecord 微信用户积分记录
     * @return 结果
     */
    @Override
    public int insertWechatUserPointsRecord(WechatUserPointsRecord wechatUserPointsRecord) {
        wechatUserPointsRecord.setCreateTime(DateUtils.getNowDate());
        return wechatUserPointsRecordMapper.insertWechatUserPointsRecord(wechatUserPointsRecord);
    }

    /**
     * 修改微信用户积分记录
     *
     * @param wechatUserPointsRecord 微信用户积分记录
     * @return 结果
     */
    @Override
    public int updateWechatUserPointsRecord(WechatUserPointsRecord wechatUserPointsRecord) {
        return wechatUserPointsRecordMapper.updateWechatUserPointsRecord(wechatUserPointsRecord);
    }

    /**
     * 批量删除微信用户积分记录
     *
     * @param ids 需要删除的微信用户积分记录主键
     * @return 结果
     */
    @Override
    public int deleteWechatUserPointsRecordByIds(Long[] ids) {
        return wechatUserPointsRecordMapper.deleteWechatUserPointsRecordByIds(ids);
    }

    /**
     * 删除微信用户积分记录信息
     *
     * @param id 微信用户积分记录主键
     * @return 结果
     */
    @Override
    public int deleteWechatUserPointsRecordById(Long id) {
        return wechatUserPointsRecordMapper.deleteWechatUserPointsRecordById(id);
    }

    /**
     * 过滤出埠参数参数
     *
     * @param wechatUserPointsRecord 微信用户积分记录对象
     * @param loginUser              当前登录对象
     * @return 返回过滤后的[微信用户积分记录对象]
     * @author KevenPotter
     * @date 2024-07-17 10:53:25
     */
    @Override
    public WechatUserPointsRecord filterInbound(WechatUserPointsRecord wechatUserPointsRecord, LoginUser loginUser) {
        return wechatUserPointsRecord;
    }

    /**
     * 过滤出埠参数参数
     *
     * @param wechatUserPointsRecord 微信用户积分记录对象
     * @param loginUser              当前登录对象
     * @return 返回过滤后的[微信用户积分记录对象]
     * @author KevenPotter
     * @date 2024-07-17 10:53:49
     */
    @Override
    public WechatUserPointsRecord filterOutbound(WechatUserPointsRecord wechatUserPointsRecord, LoginUser loginUser) {
        Long userId = wechatUserPointsRecord.getUserId();
        if (userId != null) wechatUserPointsRecord.setUserName(wechatUserService.getById(userId).getNickName());
        Long createBy = wechatUserPointsRecord.getCreateBy();
        if (createBy != null) wechatUserPointsRecord.setCreateByName(userService.selectUserById(createBy).getNickName());
        return wechatUserPointsRecord;
    }
}
